#!/usr/bin/env bash

# Copyright 2018 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

BUILD_DIR="${DIR}/../build-arm64"

function HELP {
    echo "help:"
    echo "-b <board>            : Board to flash"
    echo "-h for help"
    exit 1
}

BOARD=

while getopts "b:h:" FLAG; do
    case $FLAG in
        b) BOARD="${OPTARG}";;
        h) HELP;;
        \?)
            echo unrecognized option
            HELP
            ;;
    esac
done
shift $((OPTIND-1))


if [[ -z "${BOARD}" ]]; then
    echo must specify a board to flash
    HELP
fi

BOOT_IMG=${BUILD_DIR}/${BOARD}-boot.img
VBMETA_IMG=${BUILD_DIR}/${BOARD}-vbmeta.img

fastboot flash boot_a ${BOOT_IMG} && fastboot flash vbmeta_a ${VBMETA_IMG} && fastboot reboot
